local tianxing = fk.CreateSkill {
  name = "cf_tianxing",
  tags = { Skill.Limited },
}

Fk:loadTranslationTable {
  ["cf_tianxing"] = "天星",
  [":cf_tianxing"] = "限定技，出牌阶段，你可以选择至多X名其他角色，你对其各造成两点伤害，然后令其本回合不能使用或打出手牌且受伤加一。(X为你的攻击范围)",
  ["cf_tianxing-ask"] = "选择至多%arg名其他角色造成两点伤害，其本回合不能使用或打出手牌且受伤加一",
  ["@@cf_tianxing-turn"] = "天星",
  ["$cf_tianxing1"] = "天理长驱。",
  ["$cf_tianxing2"] = "天动万象。",
}

tianxing:addEffect("active", {
  target_num = 0,
  card_num = 0,
  can_use = function(self, player)
    return player:hasSkill(tianxing.name) and player:usedEffectTimes(tianxing.name, Player.HistoryGame) == 0
  end,
  on_cost = function(self, player, data, extra_data)
    local room = player.room
    local targets = room:askToChoosePlayers(player, {
      targets = room:getOtherPlayers(player),
      max_num = player:getAttackRange(),
      min_num = 1,
      skill_name = tianxing.name,
      prompt = tianxing.name .. "-ask:::" .. player:getAttackRange(),
      cancelable = false,
    })
    return { tos = targets }
  end,
  on_use = function(self, room, skillUseEvent)
    local tos = skillUseEvent.tos
    local player = skillUseEvent.from
    for _, p in pairs(tos) do
      room:damage({
        to = p,
        from = player,
        damage = 2,
        skillName = tianxing.name,
      })
      room:addPlayerMark(p, "@@" .. tianxing.name .. "-turn")
    end
  end
})


tianxing:addEffect("prohibit", {
  prohibit_use = function(self, player, card)
    if player:getMark("@@" .. tianxing.name .. "-turn") > 0 then
      local subcards = card:isVirtual() and card.subcards or { card.id }
      return #subcards > 0 and
          table.every(subcards, function(id)
            return table.contains(player:getCardIds("h"), id)
          end)
    end
  end,
  prohibit_response = function(self, player, card)
    if player:getMark("@@" .. tianxing.name .. "-turn") > 0 then
      local subcards = card:isVirtual() and card.subcards or { card.id }
      return #subcards > 0 and
          table.every(subcards, function(id)
            return table.contains(player:getCardIds("h"), id)
          end)
    end
  end,
})

tianxing:addEffect(fk.DamageInflicted, {
  can_refresh = function(self, event, target, player, data)
    return player:getMark("@@" .. tianxing.name .. "-turn") > 0 and player == data.to
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    data:changeDamage(1)
  end
})

return tianxing
